一 . 概述

模型评估是通过一系列评估方法评估模型的好坏。

二 . Confusion Matrix (混淆矩阵)

在机器学习领域和统计分类问题中,混淆矩阵是可视化工具,特别用于监督学习,在无监督学习一般叫做匹配矩阵。矩阵的每一列代表一个类的实例预测,而每一行表示一个实际的类的实例。之所以如此命名,是因为通过这个矩阵可以方便地看出机器是否将两个不同的类混淆了。

真真 = true 真假 = false
假真 = false 假假 = true

三 . Accuracy (准确度)

四 . Precision (准确率)

查得更准

五 . Recall (召回率)

查得更全

一般情况下 准确率 和 召回率 越高越好,但真实情况需要根据业务的情况。

六 . F1 Score

更偏向于那个指标。

七 . ROC

roc 越大模型越好

八 . sklearn 例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, roc_curve
import numpy as np

data = np.asarray(pd.read_csv('data.csv'))
x = data[:, 0:2]
y = data[:, 2]

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=42)

model = DecisionTreeClassifier()
model.fit(x_train, y_train)
y_pred = model.predict(x_test)

acc = accuracy_score(y_test, y_pred)
precision_score = precision_score(y_test, y_pred)
recall_score = recall_score(y_test, y_pred)
f1_score = f1_score(y_test, y_pred)
roc_curve = roc_curve(y_test, y_pred)

print('acc: ', acc)
print('precision_score: ', precision_score)
print('recall_score: ', recall_score)
print('f1_score: ', f1_score)
print('roc_curve: ', roc_curve)